var t = require("../../../@babel/runtime/helpers/interopRequireDefault").default, e = t(require("@vant/weapp/dialog/dialog.js")), o = t(require("../../../api/api_queryRemain.js")), a = t(require("../../../utils/Tips")), n = t(require("../../../api/wxRequest")), i = t(require("../../../behaviors/auth")), u = require("../../../utils/regs"), r = require("../../../utils/number"), c = getApp().eventBus;

Component({
    behaviors: [ i.default ],
    properties: {
        id: {
            type: String
        }
    },
    data: {
        show: !1,
        product: {},
        accountType: "qq",
        productCount: 1,
        input1Placeholder: "请输入会员到账的QQ号",
        input2Placeholder: "请再次确认会员到账的QQ号",
        confirmBtnLoading: !1
    },
    observers: {
        accountType: function(t) {
            "phone" === t ? this.setData({
                input1Placeholder: "请输入会员到账的手机号",
                input2Placeholder: "请再次确认会员到账的手机号"
            }) : this.setData({
                input1Placeholder: "请输入会员到账的QQ号",
                input2Placeholder: "请再次确认会员到账的QQ号"
            });
        }
    },
    methods: {
        init: function() {},
        handleInput1Change: function(t) {
            var e = t.detail, o = (void 0 === e ? {} : e).value, a = void 0 === o ? "" : o;
            this.setData({
                account1: a
            });
        },
        handleInput2Change: function(t) {
            var e = t.detail, o = (void 0 === e ? {} : e).value, a = void 0 === o ? "" : o;
            this.setData({
                account2: a
            });
        },
        handleCounterChange: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {
                detail: {}
            }, e = t.detail.value, o = this.data.product.normalPrice;
            this.setData({
                productCount: e,
                computedAmount: this.computeTotal(o, e)
            });
        },
        handleConfirm: function() {
            var t = this;
            if (this.testFormInput()) {
                var a = (this.data.product || {}).goodId, i = this.data, u = i.account1, r = i.account2, d = i.productCount;
                this.setData({
                    confirmBtnLoading: !0
                }, function() {
                    o.default.killCharge({
                        goodId: a,
                        accountNo: u,
                        confirmAccountNo: r,
                        num: d
                    }).then(function(o) {
                        return t.setData({
                            confirmBtnLoading: !1
                        }), console.log(o), "0" === o.code ? o.data.pkg ? n.default.wxPay(o.data) : Promise.reject("fail") : "10002" === o.code ? (e.default.confirm({
                            context: t,
                            confirmButtonText: "立即登录",
                            confirmButtonOpenType: "getPhoneNumber",
                            message: "您还未登录“王卡助手”小程序，请登录后提交"
                        }), Promise.reject("notBind")) : (e.default.alert({
                            context: t,
                            message: o.message
                        }), Promise.reject());
                    }).then(function() {
                        var e = "pages/product/product", o = getCurrentPages();
                        o[o.length - 2] && o[o.length - 2].route === e ? (c.emit("productPageRefresh", {
                            phone: t.data.phone
                        }), wx.navigateBack({
                            delta: 1
                        })) : wx.redirectTo({
                            url: "/".concat(e, "?id=").concat(t.product.goodId)
                        });
                    }).catch(function(a) {
                        console.log(a), t.setData({
                            confirmBtnLoading: !1
                        }), "fail" === a && e.default.alert({
                            context: t,
                            message: "调起支付失败，请稍候重试"
                        }), "cancel" === a && o.default.closeKillOrder();
                    });
                });
            }
        },
        testFormInput: function() {
            var t, e, o = this.data, n = o.account1, i = o.account2, r = "";
            return "phone" === o.accountType ? (t = u.phone.test(n), e = u.phone.test(i), r = "手机号") : (t = u.qq.test(n), 
            e = u.qq.test(i), r = "QQ号码"), t && e ? n === i || (a.default.toast("请保证两次输入一致"), 
            !1) : (a.default.toast("请输入正确的" + r), !1);
        },
        computeTotal: function(t, e) {
            return (0, r.divNum)((0, r.mulNum)(e, t), 100);
        }
    },
    attached: function() {
        var t = this;
        this.sub1 = c.on("toOrderConfirmPageInit", function(e) {
            var o = e.remainstock, a = e.normalPrice, n = e.tag, i = o >= 1 ? 1 : 0, u = n && "BLACK_WHALE" === n ? "phone" : "qq";
            t.setData({
                show: !0,
                product: e,
                productCount: i,
                accountType: u,
                computedAmount: t.computeTotal(a, i)
            }, function() {
                t.init();
            });
        });
    },
    detached: function() {
        this.sub1 && this.sub1.off();
    }
});